﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;


public partial class TaskTypeMasterAdmin : System.Web.UI.Page
{
 
    int transid;
  
    protected void Page_Load(object sender, EventArgs e)
    {
        GetDataGrid();
    }
    protected void btn_Clear_Click(object sender, EventArgs e)
    {
        Clear();       
    }

    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        if (Validation() == true)
        {
          
            string value,type;
            if (rbtnYes.Checked == true)
            {
                value = "Yes";

                type = (ddlFollowUp.SelectedItem).ToString();
             
            }
            else
            {
                value = "No";
                type = "";
            }

            if (gvAvailable.SelectedIndex == -1)
            {
                DALTask.SetTaskType(txtTaskName.Text, value, type,1);
            }
            else
            {
                DataTable dt = new DataTable();
                dt = DALTask.GetSetGrid();
                int count = Convert.ToInt32(gvAvailable.SelectedIndex);
                transid = Convert.ToInt32(dt.Rows[count][0]);
                DALTask.ModifyTaskType(transid,txtTaskName.Text, value, type,2);
             }
                Clear();
                GetDataGrid();

        }


    }
    private void Clear()
    {
        txtTaskName.Text = "";
        if (rbtnNo.Checked == true)

            rbtnNo.Checked = false;
        else if (rbtnYes.Checked == true)
            rbtnYes.Checked = false;
        ddlFollowUp.SelectedIndex = 0;
        gvAvailable.SelectedIndex = -1;
    }
    public bool  Validation()
    {
        if (txtTaskName.Text == "")
        {
            MessageBox.Show("Please Enter TaskName");
            return false;
        }
        if(rbtnNo.Checked==false && rbtnYes.Checked==false)
        {
           
            MessageBox.Show("Please Select FollowUp Option");
            return false;
        }
        if (rbtnYes.Checked == true)
        {
           
            if (ddlFollowUp.SelectedIndex == 0)
            {
                MessageBox.Show("Select the FollowUp Type");
                return false;
            }
        }
        return true;

    }
    public void GetDataGrid()
    {
        DataTable dt = new DataTable();
        dt = DALTask.GetSetGrid();
       
        gvAvailable.DataSource = dt;
        gvAvailable.DataBind();
    }
    protected void gvAvailable_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();

        int gVal = Convert.ToInt32(gvAvailable.SelectedDataKey.Value);
        dt = DALTask.GetGrid(gVal);
        transid = Convert.ToInt32(dt.Rows[0][0]);
        txtTaskName.Text = dt.Rows[0][1].ToString();
        if (dt.Rows[0][2].ToString() == "Yes")
        {
            rbtnYes.Checked = true;
            rbtnNo.Checked = false;
            ddlFollowUp.Enabled = true;
            if (dt.Rows[0][3].ToString() == "Complete")
            {
                ddlFollowUp.SelectedIndex = 1;
            }
            else
            {
                ddlFollowUp.SelectedIndex = 2;
            }
        }
        else
        {
            rbtnNo.Checked = true;
            rbtnYes.Checked = false;
            ddlFollowUp.SelectedIndex = 0;
            ddlFollowUp.Enabled = false;
            
        }

        
    }
   

    protected void txtTaskName_TextChanged(object sender, EventArgs e)
    {
        //transtype = 1; //type=2,3 
    }
   
    protected void ddlFollowUp_SelectedIndexChanged(object sender, EventArgs e)
    {
        //transtype = 1;
    }
}
